package com.syf.kit.enums;

import cn.hutool.core.util.StrUtil;

/**
 * 关系型数据库的类型
 */
public enum RDSType {
    MYSQL("MySQL", "mysql"),
    ORACLE("Oracle", "oracle"),
    PostgreSQL("PostgreSQL", "postgresql"),
    SQLite("SQLite", "sqlite");

    private final String rdsName;

    private final String jdbcKeyword;

    private String driveClassName;

    RDSType(String rdsName, String jdbcKeyword) {
        this.rdsName = rdsName;
        this.jdbcKeyword = jdbcKeyword;
    }

    public String getDriveClassName() {
        return driveClassName;
    }

    public void setDriveClassName(String driveClassName) {
        this.driveClassName = driveClassName;
    }

    public String getRdsName() {
        return rdsName;
    }

    public String getJdbcKeyword() {
        return jdbcKeyword;
    }

    public static RDSType getRDSTypeByName(String rdsName) {
        for (RDSType rdsType : RDSType.values()) {
            if (StrUtil.equalsIgnoreCase(rdsType.getRdsName(), rdsName)) {
                return rdsType;
            }
        }

        return MYSQL;
    }

    public static String getAllNameString() {
        StringBuilder sb = new StringBuilder();
        for (RDSType type : RDSType.values()) {
            sb.append(",").append(type.getRdsName());
        }

        return sb.substring(1);
    }
}
